package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

public class InternalPage extends AnyPage{

    @FindBy(xpath = "//nav//li[1]/a")
    public WebElement menuHomeLink;

    @FindBy(xpath = "//nav//li[2]/a")
    public WebElement menuMyProfileLink;

    @FindBy(xpath = "//nav//li[3]/a")
    public WebElement menuUserNamagementLink;

    @FindBy(xpath = "//nav//li[4]/a")
    public WebElement menuLogoutLink;

    public boolean isOnThisPage(){
        return menuLogoutLink.isDisplayed();
    }

    @Override
    void tryToOpen(){
        MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin", "admin");
    }

    public void logout() {
        menuLogoutLink.click();
        waitEvent().until(alertIsPresent()).accept();
    }

    public ProfilePage gotoUserProfilePage() {
        menuMyProfileLink.click();
        return MyPageFactory.getPage(driver, ProfilePage.class);
    }

    public MovieListPage gotoHomePage() {
        menuHomeLink.click();
        return MyPageFactory.getPage(driver, MovieListPage.class);
    }

    public UserPage gotoUserManagementConsolPage() {
        menuUserNamagementLink.click();
        return MyPageFactory.getPage(driver, UserPage.class);
    }
}
